import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

main() => runApp(MyApp());

// 生成代码快捷键  stl
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: GLHomePage(),
    );
  }
}

class GLHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        // appBar: AppBar(
        //   title: const Text("Flutter列表"),
        // ),
        body: CustomScrollView(
      slivers: [
        SliverAppBar(
          expandedHeight: 300,
          pinned: true,
          flexibleSpace: FlexibleSpaceBar(
            title: Text("Flutter列表导航"),
            background: Image.asset(
              "assets/images/scent_woman.jpg",
              fit: BoxFit.cover,
            ),
          ),
        ),
        SliverGrid(
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2,
                crossAxisSpacing: 8,
                mainAxisSpacing: 8,
                childAspectRatio: 1.5),
            delegate: SliverChildBuilderDelegate((BuildContext ctx, int index) {
              return Container(
                  color: Color.fromARGB(255, Random().nextInt(256),
                      Random().nextInt(256), Random().nextInt(256)));
            }, childCount: 20)),
        SliverList(
            delegate: SliverChildBuilderDelegate((BuildContext ctx, int index) {
          return ListTile(
            leading: Icon(Icons.people),
            title: Text("Flutter列表$index"),
          );
        }))
      ],
    ));
  }
}

class SliverGridDemo1 extends StatelessWidget {
  const SliverGridDemo1({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        SliverSafeArea(
            sliver: SliverPadding(
          padding: EdgeInsets.all(8),
          sliver: SliverGrid(
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2,
                crossAxisSpacing: 8,
                mainAxisSpacing: 8,
                childAspectRatio: 1.5),
            delegate: SliverChildBuilderDelegate((BuildContext ctx, int index) {
              return Container(
                  color: Color.fromARGB(255, Random().nextInt(256),
                      Random().nextInt(256), Random().nextInt(256)));
            }, childCount: 20), // 设置一个childCount来表示列表项的数量
          ),
        )),
      ],
    );
  }
}
